<?php
$q=$_GET["q"];
$hint='';
include_once ("../Login/databaseconnection.php");
require_once ("../Login/config.php");
$result = mysql_query("SELECT * FROM programme Where Programme_Name='$q'");
if($row = mysql_fetch_array($result))
{
$id=$row['Programme_Id'];
$hint="<br/><font color='black'>The ID of this Programme is :".$id."<br/>";
$resultpp= mysql_query("SELECT * FROM programmes Where Programme_Id='$id'");
if($rowpp = mysql_fetch_array($resultpp))
{
$hint=$hint.'<br/>To view all <a href="'.$basedir.'/Programmes/SearchProSch.php?action=programme&p='.$id.'" class="searchlinks">'.$q.'</a> Programme details<br/>';
}
$resultds = mysql_query("SELECT DISTINCT(School_Id) FROM programmes Where Programme_Id='$id'");
while($rowds= mysql_fetch_array($resultds))
{
$Sc=$rowds['School_Id'];
$hint=$hint."<br/>To view all ".$q." Programme details of ";
$resultsc = mysql_query("SELECT * FROM school Where School_Id='$Sc'");
$hint=$hint.'<a href="'.$basedir.'/Programmes/SearchProSch.php?action=school&s='.$rowds['School_Id'].'&p='.$id.'" class="searchlinks">';
if(mysql_num_rows($resultsc)>0)
{
if($rowsc=mysql_fetch_array($resultsc))
{
$address=$rowsc['Address'];
}
}
if(mysql_num_rows($resultsc)==0)
{
$hint=$hint.$Sc;
}
if(mysql_num_rows($resultsc)>0)
{
$hint=$hint.$rowsc['Name'].' in '.$rowsc['Address'];
}
$hint=$hint.'</a><br/>';
}
$resultdy = mysql_query("SELECT DISTINCT(Year) FROM programmes Where Programme_Id='$id'");
while($rowdy= mysql_fetch_array($resultdy))
{
$hint=$hint."<br/>To view all ".$q." Programme details at ";
$hint=$hint.'<a href="'.$basedir.'/Programmes/SearchProSch.php?action=year&p='.$id.'&y='.$rowdy['Year'].'" class="searchlinks">'.$rowdy['Year'].'</a><br/>';
}

$resultp = mysql_query("SELECT * FROM programmes Where Programme_Id='$id'");
while($rowp= mysql_fetch_array($resultp))
{
$S_Id=$rowp['School_Id'];
$year=$rowp['Year'];

$results = mysql_query("SELECT * FROM school Where School_Id='$S_Id'");
if(mysql_num_rows($results)>0)
{
if($rows= mysql_fetch_array($results))
{
$S_Name=$rows['Name'];
$S_Addr=$rows['Address'];
$C_No=$rows['Census_Number'];
}
}
$hint=$hint."<br/>To view the ".$q." Programme details of ";
$hint=$hint.'<a href="'.$basedir.'/Programmes/SearchProSch.php?action=programmewithschoolandyear&s='.$S_Id.'&p='.$id.'&y='.$year.'" class="searchlinks">';
if(mysql_num_rows($results)==0)
{
$hint=$hint.$S_Id;
}
if(mysql_num_rows($results)>0)
{
$hint=$hint.$S_Name.' in '.$S_Addr.', Census number '.$C_No;
}
$hint=$hint.' at '.$year.'</a><br/>';
}
$hint=$hint.'</font>';
}
if($hint==''||$hint=="<br/><font color='black'>The ID of this Programme is :".$id."<br/></font>")
{
echo $hint."<br/>";
$response='<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> There are no results found for this Programme name!</font>';
}
else
{
$response=$hint;
}
echo $response;
?>